package com.webchat.netty.gateway;

import com.webchat.netty.gateway.common.PropertyLoader;
import com.webchat.netty.gateway.config.NettyGatewayServer;
import com.webchat.netty.gateway.config.properties.NacosConfig;
import com.webchat.netty.gateway.listener.NacosEventListener;

public class NettyGatewayApplication {


    public static void main(String[] args) {

        // 设置当前启动环境配置参数
        // java -jar netty-server.jar -Denv=prod
        System.setProperty("env", "dev");

        // 初始化配置
        initProperties();
        NettyGatewayServer nettyGatewayServer = new NettyGatewayServer();
        try {
            // 1. 开启nacos netty server 实例监听
            new NacosEventListener().start();
            Thread.sleep(2000);
            // 2. 启动网关 netty server
            nettyGatewayServer.start();
        } catch (Exception e) {
            // stop gateway server
            nettyGatewayServer.stop();
        }
    }

    private static void initProperties() {

        PropertyLoader.init();

        // 初始化Nacos监听器配置
        NacosConfig nacosConfig = NacosConfig.init();
        NacosEventListener.init(nacosConfig);
    }
}
